package com.flyingocean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class pullFromWebImpl implements pullFromWeb {
	public PlayerInfo pull(String surl) {
		PlayerInfo p = new PlayerInfo();

		try {
			URL url = new URL(surl);
			InputStream is = url.openStream();
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			String line = br.readLine();

			line = br.readLine();
			while (line != null & p.l == null) {
				// System.out.println(line);
				// 进行筛选
				// 个人资料
				if (line.indexOf("全　　名:") != -1) {
					p.name = line;
				} else if (line.indexOf("位　　置:") != -1) {
					p.position = line;
				} else if (line.indexOf("身　　高:") != -1) {
					p.height = line;
				} else if (line.indexOf("体　　重:") != -1) {
					p.weight = line;
				} else if (line.indexOf("出生日期:") != -1) {
					p.birthDate = line;
				} else if (line.indexOf("出生城市:") != -1) {
					p.city = line;
				} else if (line.indexOf("大　　学:") != -1) {
					p.college = line;
				} else if (line.indexOf("球衣号码:") != -1) {
					p.number = line;
				}
				// 比赛数据
				else if (line.indexOf("<td class=\"normal season\"") != -1) {
					p.season = line;
				} else if (line.indexOf("<td class=\"normal tm\">") != -1) {
					p.tm = line;
				} else if (line.indexOf("<td class=\"normal g\">") != -1) {
					p.g = line;
				} else if (line.indexOf("<td class=\"normal gs\">") != -1) {
					p.gs = line;
				} else if (line.indexOf("<td class=\"normal mp\">") != -1) {
					p.mp = line;
				} else if (line.indexOf("<td class=\"normal fgper\">") != -1) {
					p.fgper = line;
				} else if (line.indexOf("<td class=\"normal fg\">") != -1) {
					p.fg = line;
				} else if (line.indexOf("<td class=\"normal fga\">") != -1) {
					p.fga = line;
				} else if (line.indexOf("<td class=\"normal threepper\">") != -1) {
					p.threepper = line;
				} else if (line.indexOf("<td class=\"normal threep\">") != -1) {
					p.threep = line;
				} else if (line.indexOf("<td class=\"normal threepa\">") != -1) {
					p.threepa = line;
				} else if (line.indexOf("<td class=\"normal ftper\">") != -1) {
					p.ftper = line;
				} else if (line.indexOf("<td class=\"normal ft\">") != -1) {
					p.ft = line;
				} else if (line.indexOf("<td class=\"normal fta\">") != -1) {
					p.fta = line;
				} else if (line.indexOf("<td class=\"normal trb\">") != -1) {
					p.trb = line;
				} else if (line.indexOf("<td class=\"normal orb\">") != -1) {
					p.orb = line;
				} else if (line.indexOf("<td class=\"normal drb\">") != -1) {
					p.drb = line;
				} else if (line.indexOf("<td class=\"normal ast\">") != -1) {
					p.ast = line;
				} else if (line.indexOf("<td class=\"normal stl\">") != -1) {
					p.stl = line;
				} else if (line.indexOf("<td class=\"normal blk\">") != -1) {
					p.blk = line;
				} else if (line.indexOf("<td class=\"normal tov\">") != -1) {
					p.tov = line;
				} else if (line.indexOf("<td class=\"normal pf\">") != -1) {
					p.pf = line;
				} else if (line.indexOf("<td class=\"normal pts\">") != -1) {
					p.pts = line;
				} else if (line.indexOf("<td class=\"normal w\">") != -1) {
					p.w = line;
				} else if (line.indexOf("<td class=\"normal l\">") != -1) {
					p.l = line;
				}

				line = br.readLine();
			}

			br.close();
			isr.close();
			is.close();

		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return p;

	}
}
